π‘οΈ Sentinel: [CRITICAL] Fix SQL injection in jsonExtract - #153
π‘οΈ Sentinel: [CRITICAL] Fix SQL injection in jsonExtract#153Donach wants to merge 1 commit into
Conversation
This change fixes a potential SQL injection vulnerability in `packages/core/src/db/database-wrapper.ts`. The `jsonExtract` function previously used `sql.raw` to interpolate JSON path keys into PostgreSQL `->` and `->>` operators. This bypasses Drizzle's parameterization and could allow SQL injection if the path variables ever depend on user input. The fix replaces `sql.raw` with standard string parameterization, explicitly casting the parameters to `::text` before being applied to the operators.
|
π Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a π emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
π¨ Severity: CRITICAL
π‘ Vulnerability: The
jsonExtractfunction inpackages/core/src/db/database-wrapper.tsusedsql.rawto insert JSON path keys into PostgreSQL->and->>operators without parameterization.π― Impact: Using
sql.rawdirectly injects strings into the SQL query, bypassing parameterization and creating a potential SQL injection vulnerability if any JSON path keys are derived from user input.π§ Fix: In Drizzle ORM, never use
sql.raw()to interpolate dynamic variables. To prevent SQL injection when working with PostgreSQL JSON operators (->,->>), we always explicitly cast dynamic parameters to text (e.g.,sql\->> (${key}::text)`) to properly resolve the overloaded operator type. We usedsql.jointo safely combine these parameterized template literals when chaining multi-level paths. β **Verification:** Verified by checking thatjsonExtractsafely outputs parametrized values during string interpolation.pnpm build,pnpm test, andpnpm lint` passed without issue.PR created automatically by Jules for task 11874196301144504513 started by @Donach